<template>
    <div class="portlet box blue">
        <div class="portlet-title">
            <div class="caption">
                <i class="fa fa-gift"></i>订单查询</div>
            <div class="tools">
                <a href="javascript:;" class="collapse" data-original-title="" title=""></a>
            </div>
        </div>
        <div class="portlet-body form">
            <!-- BEGIN FORM-->
            <form action="#" class="form-horizontal">
                <div class="form-body">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-md-3">支付单号</label>
                                <div class="col-md-9">
                                    <el-input placeholder="请输入您想查询的支付单号" v-model="condition.PaymentNo" clearable></el-input>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-md-3">支付类型</label>
                                <div class="col-md-9">
                                    <el-select v-model="condition.PayMethods" multiple placeholder="请选择支付类型" style="width:100%">
                                        <el-option v-for="item in words.payMethods" :key="item.code" :label="item.text" :value="item.code"></el-option>
                                    </el-select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-md-3">支付日期</label>
                                <div class="col-md-9">
                                    <el-date-picker v-model="createTimeRange" value-format="yyyy-MM-dd" type="daterange" align="right" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions" style="width:100%"></el-date-picker>
                                </div>
                            </div> 
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-md-3">审核日期</label>
                                <div class="col-md-9">
                                    <el-date-picker v-model="auditTimeRange" value-format="yyyy-MM-dd" type="daterange" align="right" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions" style="width:100%"></el-date-picker>
                                </div>
                            </div> 
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-md-3">支付人</label>
                                <div class="col-md-9">
                                    <passport-select ref="passportSelect" @PassportSelectChanged="PassportSelectChanged"></passport-select>
                                </div>
                            </div> 
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-md-3">支付状态</label>
                                <div class="col-md-9">
                                    <el-select v-model="condition.States" multiple placeholder="请选择支付状态" style="width:100%">
                                        <el-option v-for="item in words.states" :key="item.value" :label="item.text" :value="item.value"></el-option>
                                    </el-select>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-actions">
                    <div class="row">
                        <div class="col-md-12 pull-right">
                            <div style="float:right;">
                                <button type="button" class="btn green" @click="query()">查询支付单</button>
                                <button type="button" class="btn default" @click="clear()">清空条件</button>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
            <!-- END FORM-->
        </div>
    </div>
</template>

<script>

import {GetPickerShortcuts} from 'web/utils.js';
import PassportSelect from 'components/passport_select.vue';

export default {
    props: {
        'data': {
            type: Object,
            default: null
        },
    },
    components: {
        PassportSelect
    },
    data() {
        return {
            condition: {
                States: [0, 1, 11]
            },
            createTimeRange: null,
            auditTimeRange: null,
            words: {
                payMethods: [
                    { text: '银行转账', code: 'BANK'},
                    { text: '国外银行转账', code: 'BANK2'},
                    { text: '支付宝支付', code: 'ALIPAY'},
                    { text: '微信支付', code: 'WEIXIN'},
                    { text: 'PAYPAL', code: 'PAYPAL'}
                ],
                states: [
                    { text: '待审核', value:  0 },
                    { text: '已审核', value:  1 },
                    { text: '待支付', value:  10 },
                    { text: '已支付', value:  11 },                    
                    { text: '已删除', value: -1 }                  
                ]
            },
            pickerOptions: GetPickerShortcuts(),
        }
    },
    watch: {
        'data': {
            handler: function(value){
                this.condition = value;
            },
            deep: true
        },
    },
    mounted() {
        this.query();
    },
    methods: {
        query() {
            // 将时间范围分解到condition中
            let _condition = Object.assign({}, this.condition);
            if (this.createTimeRange) {
                _condition.CreateTime0 = this.createTimeRange[0];
                _condition.CreateTime1 = this.createTimeRange[1];
            }
            if (this.auditTimeRange) {
                _condition.AuditTime0 = this.auditTimeRange[0];
                _condition.AuditTime1 = this.auditTimeRange[1];
            }
            this.$emit('getCondition', _condition);
        }, 

        PassportSelectChanged(userIds) {
            this.condition.CreateUsers = userIds;
        },

        clear() {
            this.condition = {
                PassportNo: null,
                PayMethods: [],
                States: [],
                CreateUsers: []
            };
            this.createTimeRange = null;
            this.auditTimeRange = null;
            this.$refs.passportSelect.clear();
        }
    }
}
</script>

<style>

</style>
